class Solution {
public:
    vector<int> dailyTemperatures(vector<int>& temperatures) {
        int n=temperatures.size();
        stack<int> ps;
        vector<int> prev(n);//初始化为0
        //将数据放入栈中
        for(int i=0;i<n;i++){
            while(!ps.empty() && temperatures[i]>temperatures[ps.top()]){
                int temp=ps.top();
                prev[temp]=i-temp;
                ps.pop();
            }
            ps.push(i);
        }
        return prev;
    }

};